/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Golf_Manager.renderer;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Color;
/**
 *
 * @author Administrator
 */
public class ColorColumnRenderer extends DefaultTableCellRenderer 
{
    private String tableName;
    
   
   public ColorColumnRenderer(String tableName) {
      super(); 
      this.tableName = tableName;
   }
     
   public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column) {
      Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      
      if(this.tableName.equals("joinMemberTable") && column == 1){
          if(value != null && !String.valueOf(value).equals("")){
              if(isSelected){
                    cell.setBackground( new Color(184, 207, 229) );
                } else {
                    cell.setBackground( Color.WHITE );
                }
          } else {
              cell.setBackground( Color.LIGHT_GRAY );
          }
            //cell.setForeground( fgndColor );
      } else if(this.tableName.equals("groupTable")){
          Golf_Manager.model.GroupModel groupModel =  (Golf_Manager.model.GroupModel)table.getModel();
          Golf_Manager.vo.Group group = groupModel.getGroup(row);
          int groupMemberCnt = group.getGroupMemberCnt();
          
          if(column == 2){
            if(groupMemberCnt < 2){
                cell.setBackground( Color.BLACK );
            } else {
                if(isSelected){
                    cell.setBackground( new Color(184, 207, 229) );
                } else {
                    cell.setBackground( Color.WHITE );
                }
            }
          }
          if(column == 3){
            if(groupMemberCnt < 3){
                cell.setBackground( Color.BLACK );
            } else {
                if(isSelected){
                    cell.setBackground( new Color(184, 207, 229) );
                } else {
                    cell.setBackground( Color.WHITE );
                }
            }
          }
          if(column == 4){
            if(groupMemberCnt < 4){
                cell.setBackground( Color.BLACK );
            } else {
                if(isSelected){
                    cell.setBackground( new Color(184, 207, 229) );
                } else {
                    cell.setBackground( Color.WHITE );
                }
            }
          }
      }
      
      return cell;
   }
}

